package com.xsh.gls.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.sun.tools.corba.se.idl.constExpr.Or;
import com.xsh.gls.pojo.*;
import com.xsh.gls.service.*;

import com.xsh.gls.pojo.Order;
import com.xsh.gls.pojo.Salesman;
import com.xsh.gls.pojo.Transfer;
import com.xsh.gls.pojo.User;
import com.xsh.gls.pojo.*;
import com.xsh.gls.service.*;
import com.xsh.gls.utils.AlipayConfig;

import com.xsh.gls.service.BookingService;

import com.xsh.gls.service.OrderService;
import com.xsh.gls.service.YconService;
import com.xsh.gls.service.SalManService;
import com.xsh.gls.service.UserService;
import com.xsh.gls.service.SalesmanService;

import com.xsh.gls.utils.Constant;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.text.SimpleDateFormat;
import java.util.*;

import static java.math.BigDecimal.ROUND_HALF_DOWN;

@RestController
@RequestMapping(value = "/OrderController")
public class OrderController {
@Autowired
private OrderService orderService;
    @Autowired
    private SalManService salManService;
@Autowired
 private    UserService userService;
    //查询所有订单的方法
    @Autowired
    private BookingService bookingService;
    @Autowired
    private YconService yconService;

    @Autowired
    private DepotService depotService;

@Autowired
    SalesmanService salesmanService;

    @Autowired
    QuoteService quoteService;
//查询所有订单的方法
    @RequestMapping(value = "orderSelect")
    public Object orderSelect(@RequestParam(required = false)String orderNumber, @RequestParam(required = false)String pageNum,
                              HttpServletRequest request, HttpServletResponse response){
        List<Order> orderList=null;
        Integer _pageNum=1;
        if(pageNum!=null&&!pageNum.equals("")){
            _pageNum=Integer.parseInt(pageNum);
            if(_pageNum<=0){
                _pageNum=1;
            }
        }
        PageHelper.startPage(_pageNum, Constant.PAGESIZE, "FINSHTIME desc");

        try {
            System.out.println(orderNumber);
            orderList=orderService.selectByPrimaryKey(orderNumber);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        PageInfo<Order> page=new PageInfo<Order>(orderList);

        /* List<Depot> list=page.getList();*/
        return page;
    }

    @RequestMapping(value = "select")
    public Object select(@RequestParam(required = false)String orderNumber, @RequestParam(required = false)String pageNum,
                              HttpServletRequest request, HttpServletResponse response){
        List<Order> orderList=null;
        System.out.println(orderNumber);
        Integer _pageNum=1;
        if(pageNum!=null&&!pageNum.equals("")){
            _pageNum=Integer.parseInt(pageNum);
            if(_pageNum<=0){
                _pageNum=1;
            }
        }
        PageHelper.startPage(_pageNum, Constant.PAGESIZE, "STATUSID desc,ORDERTIME ");

        try {
            System.out.println(orderNumber);
            orderList=orderService.selectByOrNo(orderNumber);
        } catch (Exception e) {
            e.printStackTrace();
        }
        PageInfo<Order> page=new PageInfo<Order>(orderList);
        return page;
    }

    @RequestMapping(value = "selectByNo")
    public Object selectByNo(@RequestParam(required = false)String orderNumber, @RequestParam(required = false)String pageNum,
                         HttpServletRequest request, HttpServletResponse response){
        List<Order> orderList=null;
        System.out.println(orderNumber);
        Integer _pageNum=1;
        Integer salId=((User) request.getAttribute("user")).getSalid();
        if(pageNum!=null&&!pageNum.equals("")){
            _pageNum=Integer.parseInt(pageNum);
            if(_pageNum<=0){
                _pageNum=1;
            }
        }
        PageHelper.startPage(_pageNum, Constant.PAGESIZE, "ORDERTIME desc");

        try {
            orderList=orderService.selectByNo(orderNumber,salId);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        PageInfo<Order> page=new PageInfo<Order>(orderList);
        return page;
    }

    @RequestMapping("/update")
    public Transfer update(Order order){
        Transfer transfer=new Transfer();
        Terms terms=null;
        boolean falg=true;
         terms= quoteService.getByDTran(order.getCountry(),null);
        if(terms!=null) {
            double unitprice = terms.getUnitprice().doubleValue();
            double fuel = terms.getFuel().doubleValue();
            double money = (order.getGoodWeight() * unitprice) / fuel;
            if (order.getAddServices() != null || !order.getAddServices().equals("")) {
                money += Integer.valueOf(order.getAddServices());
            }
            order.setMoney(money);
        }else{
           falg=false;
        }if (falg){
        boolean boo=orderService.update(order);

        if(boo){
            transfer.setMessage("yes");
            System.out.println("修改成功");
        }else{
            transfer.setMessage("no");
            System.out.println("修改失败");
        }}else{
            transfer.setMessage("noadd");
        }
        return transfer;
    }

    @RequestMapping("/insert")
    public Object sel(){
        List<User> users=userService.selectByTypeID(5);
        return users;
    }
    //下单方法
    @RequestMapping(value = "insertOrder")
    public Transfer insertOrder(Order order,HttpServletRequest request){
        Transfer transfer=new Transfer();
        boolean falg=true;
        order.setStatusid(1);
        Date date=new Date();
        order.setCreatetime(date);
        order.setCustomerId(((User)request.getAttribute("user")).getCusid());
        order.setOrderNumber("GY"+String.valueOf(date.getTime()).substring(String.valueOf(date.getTime()).length()-4,String.valueOf(date.getTime()).length()-1)+UUID.randomUUID().toString().replace("-","").substring(0,2));
        Terms terms= quoteService.getByDTran(order.getCountry(),null);
        if(terms!=null) {
        double unitprice=terms.getUnitprice().doubleValue();
        double fuel=terms.getFuel().doubleValue();
        double money=(order.getGoodWeight()*unitprice)/fuel;
        if(order.getAddServices()!=null&&!order.getAddServices().equals("")){
            money+=Integer.valueOf(order.getAddServices());
        }
        order.setMoney(money);
        }else{

            falg=false;
        }
        if (falg){
        try {

            if (orderService.insertSelective(order)>0){
                transfer.setMessage("yes");
            }else{
                transfer.setMessage("no");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        }else{
            transfer.setMessage("noadd");
        }
        return  transfer;
    }

    //查询个人订单的方法
    @RequestMapping(value = "orderSeletctByOwn")
    public Object orderSelectByOwn(@RequestParam(required = false)String orderNumber,
                              @RequestParam(required = false)String pageNum,
                              HttpServletRequest request, HttpServletResponse response){
        List<Order> orderList=null;
        Integer _pageNum=1;
        if(pageNum!=null&&!pageNum.equals("")){
            _pageNum=Integer.parseInt(pageNum);
            if(_pageNum<=0){
                _pageNum=1;
            }
        }
        try {
            PageHelper.startPage(_pageNum,5, "CREATETIME desc");
            User user=(User) request.getAttribute("user");
            int CusId=user.getCusid();
            orderList=orderService.orderSelectByOwn(orderNumber,CusId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        PageInfo<Order> page=new PageInfo<Order>(orderList);

        /* List<Depot> list=page.getList();*/
        return page;
    }

    @RequestMapping("/selectByN")
    public Object selectByN(Integer id){
        Order order=null;
        order=orderService.selectByN(id);
        return order;
    }
    @RequestMapping(value = "/queryorderbyid")
    public Order queryorderbyid(Integer ordid){
        Order order=null;
        try {
            order=orderService.queryOrderById(ordid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return order;
    }
    @RequestMapping(value = "/finshUpdate")
    public Transfer finshUpdate(String ordno){
        Order order=new Order();
        Transfer transfer=new Transfer();
        try {
            order.setFinshtime(new Date());
            order.setOrderNumber(ordno);
            if(orderService.finshUpdate(order)){
                transfer.setMessage("yes");
            }else{
                transfer.setMessage("no");
            }
        } catch (Exception e) {
            e.printStackTrace();
            transfer.setMessage("no");
        }
        return transfer;
    }

    @RequestMapping("/forfinshUpdate")
    public Transfer forfinshUpdate(String[] checkIDs){
        Transfer transfer=new Transfer();
        try {
            if(orderService.forfinshUpdate(checkIDs)){
                transfer.setMessage("yes");
            }else{
                transfer.setMessage("no");
            }
        } catch (Exception e) {
            e.printStackTrace();
            transfer.setMessage("no");
        }
        return transfer;
    }
    @RequestMapping("/sys_Receipt")
    public Object sys_Receipt(Order order,HttpServletRequest request,@RequestParam(required = false)String pageNum){
        List<Order> list=null;
        Integer _pageNum=1;
        if(pageNum!=null&&!pageNum.equals("")){
            _pageNum=Integer.parseInt(pageNum);
            if(_pageNum<=0){
                _pageNum=1;
            }
        }
        try {

          Integer salid=((User)request.getAttribute("user")).getSalid();
          String area=salesmanService.queryareaById(salid).replace("_","");
          order.setCity(area);
            PageHelper.startPage(_pageNum, 5, "CREATETIME desc");
            list=orderService.queryOrderByEare(order);
        } catch (Exception e) {
            e.printStackTrace();
        }
        PageInfo<Order> page=new PageInfo<Order>(list);

        return page;
    }


    @RequestMapping("/salman")
    public Object salman(HttpServletRequest request){
        List<Salesman> list=null;
        Integer _pageNum=1;
        try {
            String area=((User)request.getAttribute("user")).getsAddress();
            list=salManService.queryarea(area);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }


@RequestMapping("/ShowClient")
public Object ShowClient(HttpServletRequest request){
    List<Salesman> list=null;
    String area=((User)request.getAttribute("user")).getsAddress();
    String sName=((User)request.getAttribute("user")).getsName();
    try {
        list=salManService.queryarea(area);
        Iterator<Salesman> it=list.iterator();
        while (it.hasNext()){
            if (sName.equals(it.next().getsName())){
                    it.remove();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}

    @RequestMapping("/Client")
    public Object Client(String orderId,String SalesId,HttpServletRequest request){
        Transfer transfer=new Transfer();
        if (SalesId!=null){
           Order order=new Order();
           order.setSalesmanid(Integer.parseInt(SalesId));
           order.setId(Integer.parseInt(orderId));
           transfer.setMessage("false");
           if(orderService.updateByPrimaryKeySelective(order)==true){
               transfer.setMessage("true");
           }
       }
        return transfer;
    }






    //查询订单下发页面
    @RequestMapping(value = "faOrder")
    public Object faOrder(@RequestParam(required = false)String orderNumber,@RequestParam(required = false)Integer bookingid,
                          @RequestParam(required = false)Integer statusid,@RequestParam(required = false)String exportorgname,
                          @RequestParam(required = false)Integer salesmanid,@RequestParam(required = false)String customerName,
                                   @RequestParam(required = false)String pageNum){
        System.out.println("传入的查询下发订单页面的属性:\t\t\t"+orderNumber+"\t"+bookingid+"\t"+statusid+"\t"+exportorgname+"\t"+salesmanid+"\t"+customerName);
        List<Order> orderList = null;
        Integer _pageNum=1;
        if(pageNum!=null&&!pageNum.equals("")){
            _pageNum=Integer.parseInt(pageNum);
            if(_pageNum<=0){
                _pageNum=1;
            }
        }
        PageHelper.startPage(_pageNum,5, "FINSHTIME desc");
        orderList = orderService.getOrderAll(orderNumber, bookingid, statusid, exportorgname, salesmanid, customerName);
        PageInfo<Order> page=new PageInfo<Order>(orderList);
        return page;
    }


    /*进行下发*/
    @RequestMapping("/xiafa")
    public Transfer xiafa(@RequestParam(required = false)String orderNumber) {
        Transfer transfer = new Transfer();
        Order order = orderService.getByOrderNo(orderNumber);
        if (order == null){
            transfer.setMessage("no");
        }else {
            order.setStatusid(20);
            order.setOrderNumber(orderNumber);
            order.setBookingid(order.getBookingid());
            if (orderService.updateByorderNumber(order)){
                transfer.setMessage("yes");
            }else {
                transfer.setMessage("no");
            }
        }
        return transfer;
    }


    /*进行集拼下发*/
    @RequestMapping("/allxiafa")
    public Transfer allxiafa(@RequestParam(required = false)Integer spelnos) {
        Transfer transfer = new Transfer();
        if (orderService.getByspelnos(spelnos)){
            transfer.setMessage("yes");
        }else {
            transfer.setMessage("no");
        }

        return transfer;
    }



    /*进行挂起*/
    @RequestMapping("/guaqi")
    public Transfer guaqi(@RequestParam(required = false)String orderNumber) {
        Transfer transfer = new Transfer();
        Order order = orderService.getByOrderNo(orderNumber);
        if (order == null){
            transfer.setMessage("no");
        }else {
            order.setStatusid(21);
            order.setOrderNumber(orderNumber);
            order.setBookingid(order.getBookingid());
            if (orderService.updateByorderNumber(order)){
                transfer.setMessage("yes");
            }else {
                transfer.setMessage("no");
            }
        }
        return transfer;
    }

    /*进行取消挂起*/
    @RequestMapping("/noguaqi")
    public Transfer noguaqi(@RequestParam(required = false)String orderNumber) {
        Transfer transfer = new Transfer();
        Order order = orderService.getByOrderNo(orderNumber);
        if (order == null){
            transfer.setMessage("no");
        }else {
            order.setStatusid(35);
            order.setOrderNumber(orderNumber);
            order.setBookingid(order.getBookingid());
            if (orderService.updateByorderNumber(order)){
                transfer.setMessage("yes");
            }else {
                transfer.setMessage("no");
            }
        }
        return transfer;
    }




    /*查询订单详细信息,查询订单*/
    @RequestMapping("/showOrderAll")
    public Object showOrderAll(@RequestParam(required = false)String orderNumber) {
        System.out.println("订单号\t\t"+orderNumber);
        Order order = orderService.getByNewOrderNo(orderNumber);
        return order;
    }


    /*查询订单详细信息,查询订单的订舱*/
    @RequestMapping("/showOrderBooking")
    public Object showOrderBooking(@RequestParam(required = false)Integer bookingno) {
        System.out.println("订舱号\t\t"+bookingno);
        Booking booking = bookingService.selectByPrimaryKey(bookingno);
        return booking;
    }



    /*查询订单详细信息,查询订单的预排柜*/
    @RequestMapping("/showOrderYcon")
    public Object showOrderYcon(@RequestParam(required = false)Integer yconId) {
        System.out.println("预排柜号\t\t"+yconId);
        Ycon ycon = yconService.getByYconId(yconId);
        return ycon;
    }



    /*进行驳回订单*/
    @RequestMapping("/bohui")
    public Transfer bohui(@RequestParam(required = false)String[] orderNumber) {
        System.out.println("订单号是：\t\t"+orderNumber);
        Transfer transfer = new Transfer();
        if (orderService.getByLWOrderNo(orderNumber)){
            transfer.setMessage("yes");
        }else {
            transfer.setMessage("no");
        }
        return transfer;
    }


    /*进行订单出库*/
    @RequestMapping("/chuku")
    public Transfer chuku(@RequestParam(required = false)String orderNumber) {
        Transfer transfer = new Transfer();
        Order order = orderService.getByOrderNo(orderNumber);
        if (order.getDepotid()!=null){
            order.setStatusid(31);
            order.setOuttime(new Date());
            if (orderService.updatechuku(order)){
                transfer.setMessage("yes");
            }else {
                transfer.setMessage("no");
            }
        }else {
            transfer.setMessage("no");
        }
        return transfer;
    }

    /*跳转订单入库,查询仓库名字*/
    @RequestMapping("/showDepot")
    public Object showDepot(@RequestParam(required = false)String orderNumber) {
        Order order = orderService.getByOrderNo(orderNumber);
        String depotarea = null;
        if (order.getBookingid()==null){
             depotarea = order.getCity().substring(0,2);
        }else {
             depotarea = order.getAddressee().substring(0,2);
        }
        System.out.println("订单区域\t\t\t"+depotarea);
        List<Depot> depotList = depotService.getByLWdepotarea(depotarea);
        return depotList;
    }


    /*进行订单入库*/
    @RequestMapping("/ruku")
    public Transfer ruku(@RequestParam(required = false)String orderNumber,@RequestParam(required = false)Integer depotid) {
        Transfer transfer = new Transfer();
        Order order = orderService.getByOrderNo(orderNumber);
        if (order.getDepotid()!=null){
            transfer.setMessage("no");
        }else {
            order.setIntime(new Date());
            order.setDepotid(depotid);
            order.setStatusid(33);
            if (orderService.updateruku(order)){
                transfer.setMessage("yes");
            }else {
                transfer.setMessage("no");
            }
        }
        return transfer;
    }


    //查询订单中心的方法
    @RequestMapping(value = "orderCenter")
    public Object orderCenter(Order order, @RequestParam(required = false)String pageNum,
                              HttpServletRequest request, HttpServletResponse response){
        List<Order> orderList=null;
        Integer _pageNum=1;
        if(pageNum!=null&&!pageNum.equals("")){
            _pageNum=Integer.parseInt(pageNum);
            if(_pageNum<=0){
                _pageNum=1;
            }
        }
        User user=(User) request.getAttribute("user");
        int salid=user.getSalid();
        int salidTypeId=user.getTypeid();
        Salesman salesman=salesmanService.selectByPrimaryKey(salid);
        PageHelper.startPage(_pageNum, Constant.PAGESIZE,"CREATETIME desc" );
        Order order2=new Order();
        if (order!=null){
            order2=order;
        }
        try {
            System.out.println(order2.getCreatetime());
            String sAddress=salesman.getsAddress().replace("_","");
            System.out.println(sAddress);
            String adminIdString=null;

            if (salidTypeId==Constant.ADMINID){
                sAddress=null;
                order2.setCity(sAddress);
                orderList=orderService.orderCenter(order2);
            }else if(salidTypeId==3){
                order2.setCity(sAddress);
                order2.setStatusid(Constant.MISSEDORDER);
                orderList=orderService.orderCenter(order2);
            }else if(salidTypeId==4){
                order2.setStatusid(31);
                order2.setState((sAddress.substring(0,2)));
                orderList=orderService.orderCenter(order2);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        PageInfo<Order> page=new PageInfo<Order>(orderList);

        /* List<Depot> list=page.getList();*/
        return page;
    }
@RequestMapping("/alipay")
    public String alipay(HttpServletRequest request){
    //获得初始化的AlipayClient
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);

    //设置请求参数
    AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
    alipayRequest.setReturnUrl(AlipayConfig.return_url);
    alipayRequest.setNotifyUrl(AlipayConfig.notify_url);

    //商户订单号，商户网站订单系统中唯一订单号，必填
    String out_trade_no = null;
    String total_amount=null;
    String subject=null;
    String body=null;
    try {
        out_trade_no = new String(request.getParameter("WIDout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
        //付款金额，必填
        total_amount = new String(request.getParameter("WIDtotal_amount").getBytes("ISO-8859-1"),"UTF-8");
        //订单名称，必填
         subject = new String(request.getParameter("WIDsubject").getBytes("ISO-8859-1"),"UTF-8");
        //商品描述，可空
         body = new String(request.getParameter("WIDbody").getBytes("ISO-8859-1"),"UTF-8");

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
            + "\"total_amount\":\""+ total_amount +"\","
            + "\"subject\":\""+ subject +"\","
            + "\"body\":\""+ body +"\","
            + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");

    //若想给BizContent增加其他可选请求参数，以增加自定义超时时间参数timeout_express来举例说明
    //alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
    //		+ "\"total_amount\":\""+ total_amount +"\","
    //		+ "\"subject\":\""+ subject +"\","
    //		+ "\"body\":\""+ body +"\","
    //		+ "\"timeout_express\":\"10m\","
    //		+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
    //请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节

    //请求
    String result = null;
    try {
        result = alipayClient.pageExecute(alipayRequest).getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }

    //输出
    return result;
}

    @RequestMapping("/topay")
    public Order topay(String id) {
        Order order=null;
        try {
             order=orderService.selectByPay(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return order;
    }

    @RequestMapping("/jiedan")
    public Transfer jiedan(String orderNumber,HttpServletRequest request) {
        Transfer transfer = new Transfer();
        Order order=orderService.getByOrderNo(orderNumber);
        order.setSalesmanid(((User)request.getAttribute("user")).getSalid());
        try {
            order.setOrdertime(new Date());
            if (orderService.updateJiedan(order)){
                transfer.setMessage("yes");
            }else {
                transfer.setMessage("no");
            }
        } catch (Exception e) {
            e.printStackTrace();
            transfer.setMessage("no");
        }

        return transfer;
    }

    @RequestMapping("/alljiedan")
    public Transfer alljiedan(String[] orderNumber,HttpServletRequest request) {
        Transfer transfer = new Transfer();
       Integer salemanid =  ((User)request.getAttribute("user")).getSalid();
        try {
            if (orderService.updateAllJiedan(orderNumber,salemanid)){
                transfer.setMessage("yes");
            }else {
                transfer.setMessage("no");
            }
        } catch (Exception e) {
            e.printStackTrace();
            transfer.setMessage("no");
        }

        return transfer;
    }


    @RequestMapping("/successPay")
    public Object successPay(HttpServletRequest request) {
// 获取支付宝GET过来反馈信息
        Map<String, String> params = new HashMap<String, String>();
        Map<String, String[]> requestParams = request.getParameterMap();
        for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
            }
            // 乱码解决，这段代码在出现乱码时使用
            try {
                valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            params.put(name, valueStr);
        }

        boolean signVerified = false;
        try {
            signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        } // 调用SDK验证签名

        // ——请在这里编写您的程序（以下代码仅作参考）——
        String out_trade_no = "";
        if (signVerified) {
            // 商户订单号

            // 支付宝交易号
            String trade_no = "";
            // 付款金额
            String total_amount = "";
            try {
                out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");

                trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"), "UTF-8");

                total_amount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"), "UTF-8");

                System.out.println("trade_no:" + trade_no + "<br/>out_trade_no:" + out_trade_no + "<br/>total_amount:"
                        + total_amount);

                // ==========添加交易记录==============

                /*
                    将记录存入数据库，并进行其他业务操作
                */
                orderService.updatepay(out_trade_no);

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } finally {
                return "<script>window.location='http://localhost:8082/MyOrder.html'</script>";
            }
        } else {
            System.out.println("验签失败");
            return "<script>window.location='pay.html?id="+out_trade_no+"'</script>";

        }
    }

    @RequestMapping("/echarts")
    public List<Order> echarts(@RequestParam(required = false) String finshtime){
        List<Order> list = orderService.selectecharts(finshtime);
        //这里把“类别名称”和“销量”作为两个属性封装在一个Product类里，每个Product类的对象都可以看作是一个类别（X轴坐标值）与销量（Y轴坐标值）的集合

        return list;
    }

}
